package cn.framelife.rainbow.util;

import java.sql.Connection;
import java.util.HashMap;
import java.util.Map;

import cn.framelife.rainbow.db.entity.ConnectionProperty;

/**
 * 数据库及其表名称缓存
 * @author pgwei
 *
 */
public class DatabaseCache {
	private static DatabaseCache singleton = new DatabaseCache();

	private static Map<String, Object> cache = new HashMap<String, Object>();

	public static DatabaseCache getInstance() {
		return singleton;
	}

	public Object get(String key) {
		return cache.get(key);
	}

	public Boolean hasKey(String key) {
		return cache.containsKey(key);
	}

	public void clear() {
		cache.clear();
	}
	
	/**
	 * 缓存数据库连接属性
	 *
	 * @param ConnectionProperty
	 */
	public static void setConnectionProperty(ConnectionProperty connectionProperty){
		cache.put("connectionProperty", connectionProperty);
	}
	
	public static ConnectionProperty getConnectionProperty(){
		return (ConnectionProperty)cache.get("connectionProperty");
	}
	
	/**
	 * 缓存当前数据库连接
	 *
	 * @param connection
	 */
	public static void setConnection(Connection connection){
		cache.put("connection", connection);
	}
	
	public static Connection getConnection(){
		return (Connection)cache.get("connection");
	}
}
